home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / hp300ux-xdep.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  6KB  |  231 lines

  1. /* HP/UX interface for HP 300's, for GDB when running under Unix.
  2.    Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
  3.    
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "frame.h"
  24. #include "inferior.h"
  25.  
  26. /* Defining this means some system include files define some extra stuff.  */
  27. #define WOPR
  28. #include <sys/param.h>
  29. #include <sys/dir.h>
  30. #include <signal.h>
  31. #include <sys/user.h>
  32. #include <sys/ioctl.h>
  33. #include <fcntl.h>
  34.  
  35. #include <sys/ptrace.h>
  36. #include <sys/reg.h>
  37. #include <sys/trap.h>
  38.  
  39. #include "gdbcore.h"
  40.  
  41. #include <sys/file.h>
  42. #include <sys/stat.h>
  43.  
  44. #define INFERIOR_AR0(u)                            \
  45.   ((ptrace                                \
  46.     (PT_RUAREA, inferior_pid, ((char *) &u.u_ar0 - (char *) &u), 0))    \
  47.    - KERNEL_U_ADDR)
  48.  
  49. static void
  50. fetch_inferior_register (regno, regaddr)
  51.      register int regno;
  52.      register unsigned int regaddr;
  53. {
  54. #ifndef HPUX_VERSION_5
  55.   if (regno == PS_REGNUM)
  56.     {
  57.       union { int i; short s[2]; } ps_val;
  58.       int regval;
  59.       
  60.       ps_val.i = (ptrace (PT_RUAREA, inferior_pid, regaddr, 0));
  61.       regval = ps_val.s[0];
  62.       supply_register (regno, ®val);
  63.     }
  64.   else
  65. #endif /* not HPUX_VERSION_5 */
  66.     {
  67.       char buf[MAX_REGISTER_RAW_SIZE];
  68.       register int i;
  69.       
  70.       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
  71.     {
  72.       *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid, regaddr, 0);
  73.       regaddr += sizeof (int);
  74.     }
  75.       supply_register (regno, buf);
  76.     }
  77.   return;
  78. }
  79.  
  80. static void
  81. store_inferior_register_1 (regno, regaddr, value)
  82.      int regno;
  83.      unsigned int regaddr;
  84.      int value;
  85. {
  86.   errno = 0;
  87.   ptrace (PT_WUAREA, inferior_pid, regaddr, value);
  88. #if 0
  89.   /* HP-UX randomly sets errno to non-zero for regno == 25.
  90.      However, the value is correctly written, so ignore errno. */
  91.   if (errno != 0)
  92.     {
  93.       char string_buf[64];
  94.       
  95.       sprintf (string_buf, "writing register number %d", regno);
  96.       perror_with_name (string_buf);
  97.     }
  98. #endif
  99.   return;
  100. }
  101.  
  102. static void
  103. store_inferior_register (regno, regaddr)
  104.      register int regno;
  105.      register unsigned int regaddr;
  106. {
  107. #ifndef HPUX_VERSION_5
  108.   if (regno == PS_REGNUM)
  109.     {
  110.       union { int i; short s[2]; } ps_val;
  111.       
  112.       ps_val.i = (ptrace (PT_RUAREA, inferior_pid, regaddr, 0));
  113.       ps_val.s[0] = (read_register (regno));
  114.       store_inferior_register_1 (regno, regaddr, ps_val.i);
  115.     }
  116.   else
  117. #endif /* not HPUX_VERSION_5 */
  118.     {
  119.       char buf[MAX_REGISTER_RAW_SIZE];
  120.       register int i;
  121.       extern char registers[];
  122.       
  123.       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
  124.     {
  125.       store_inferior_register_1
  126.         (regno, regaddr,
  127.          (*(int *) ®isters[(REGISTER_BYTE (regno)) + i]));
  128.       regaddr += sizeof (int);
  129.     }
  130.     }
  131.   return;
  132. }
  133.  
  134. void
  135. fetch_inferior_registers (regno)
  136.      int regno;
  137. {
  138.   struct user u;
  139.   register int regno;
  140.   register unsigned int ar0_offset;
  141.   
  142.   ar0_offset = (INFERIOR_AR0 (u));
  143.   if (regno == -1)
  144.     {
  145.       for (regno = 0; (regno < FP0_REGNUM); regno++)
  146.     fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
  147.       for (; (regno < NUM_REGS); regno++)
  148.     fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
  149.     }
  150.   else
  151.     fetch_inferior_register (regno,
  152.                  (regno < FP0_REGNUM
  153.                   ? REGISTER_ADDR (ar0_offset, regno)
  154.                   : FP_REGISTER_ADDR (u, regno)));
  155. }
  156.  
  157. /* Store our register values back into the inferior.
  158.    If REGNO is -1, do this for all registers.
  159.    Otherwise, REGNO specifies which register (so we can save time).  */
  160.  
  161. store_inferior_registers (regno)
  162.      register int regno;
  163. {
  164.   struct user u;
  165.   register unsigned int ar0_offset;
  166.   extern char registers[];
  167.  
  168.   if (regno >= FP0_REGNUM)
  169.     {
  170.       store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
  171.       return;
  172.     }
  173.   
  174.   ar0_offset = (INFERIOR_AR0 (u));
  175.   if (regno >= 0)
  176.     {
  177.       store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
  178.       return;
  179.     }
  180.  
  181.   for (regno = 0; (regno < FP0_REGNUM); regno++)
  182.     store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
  183.   for (; (regno < NUM_REGS); regno++)
  184.     store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
  185.   return;
  186. }
  187.  
  188.  
  189. /* Take the register values out of a core file and store
  190.    them where `read_register' will find them.  */
  191.  
  192. #ifdef HPUX_VERSION_5
  193. #define e_PS e_regs[PS]
  194. #define e_PC e_regs[PC]
  195. #endif /* HPUX_VERSION_5 */
  196.  
  197. void
  198. fetch_core_registers (core_reg_sect, core_reg_size, which)
  199.      char *core_reg_sect;
  200.      int core_reg_size;
  201.      int which;
  202. {
  203.   int val, regno;
  204.   struct user u;
  205.   struct exception_stack *pes = (struct exception_stack *) core_reg_sect;
  206. #define es (*pes)
  207.   char *buf;
  208.  
  209.   if (which == 0) {
  210.     if (core_reg_size < 
  211.           ((char *) &es.e_offset - (char *) &es.e_regs[R0]))
  212.       error ("Not enough registers in core file");
  213.     for (regno = 0; (regno < PS_REGNUM); regno++)
  214.       supply_register (regno, &es.e_regs[regno + R0]);
  215.     val = es.e_PS;
  216.     supply_register (regno++, &val);
  217.     supply_register (regno++, &es.e_PC);
  218.  
  219.   } else if (which == 2) {
  220.  
  221.     /* FIXME: This may not work if the float regs and control regs are
  222.        discontinuous.  */
  223.     for (regno = FP0_REGNUM, buf = core_reg_sect;
  224.      (regno < NUM_REGS);
  225.      buf += REGISTER_RAW_SIZE (regno), regno++)
  226.       {
  227.     supply_register (regno, buf);
  228.       }
  229.   }
  230. }
  231.